package com.lemon.tankgame3;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;


/**
 * @author 软柠柠吖
 * @date 2022/1/19
 */
public class LemonTankGame03 extends JFrame {
    private MyPanel myPanel = null;
    static Scanner myScanner = new Scanner(System.in);

    public static void main(String[] args) {

        new LemonTankGame03();
    }

    public LemonTankGame03() {
        System.out.println("请输入选择：1-新游戏 ~ 2-继续上局");
        String key = myScanner.next();
        myPanel = new MyPanel(key);
        Thread thread = new Thread(myPanel);
        thread.start();
        this.add(myPanel);// 把面板(就是游戏的绘图区域)
        this.addKeyListener(myPanel);// 让JFrame 监听myPanel的键盘事件
        this.setSize(1350, 800);
        this.setLocation(190, 160);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        // 在 JFrame 中增加响应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.keepRecord();
                System.exit(0);
            }
        });
    }
}
